{
  "cells": [
    {
      "attachments": {},
      "cell_type": "markdown",
      "metadata": {
        "id": "tPZFjbUDTwYE"
      },
      "source": [
        "# Stable Animation notebook"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "enjwV3WW1yxL"
      },
      "outputs": [],
      "source": [
        "#@title Install the Stability SDK\n",
        "%%capture captured --no-stderr\n",
        "%pip install stability-sdk[anim_ui]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "LUMF8i8BTwYH"
      },
      "outputs": [],
      "source": [
        "#@title Mount Google Drive\n",
        "try:\n",
        "    from google.colab import drive\n",
        "    drive.mount('/content/gdrive')\n",
        "    outputs_path = \"/content/gdrive/MyDrive/AI/StableAnimation\"\n",
        "    !mkdir -p $outputs_path\n",
        "except:\n",
        "    outputs_path = \".\"\n",
        "print(f\"Animations will be saved to {outputs_path}\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "tgZBrk8DTwYI"
      },
      "outputs": [],
      "source": [
        "#@title Connect to the Stability API\n",
        "import getpass\n",
        "from stability_sdk.api import Context\n",
        "from stability_sdk.animation_ui import create_ui\n",
        "\n",
        "# @markdown To get your API key visit https://dreamstudio.ai/account\n",
        "STABILITY_HOST = \"grpc.stability.ai:443\" #@param {type:\"string\"}\n",
        "STABILITY_KEY = getpass.getpass('Enter your API Key')\n",
        "\n",
        "# Connect to Stability API\n",
        "context = Context(STABILITY_HOST, STABILITY_KEY)\n",
        "\n",
        "# Test the connection\n",
        "context.get_user_info()\n",
        "print(\"Connection successful!\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "cellView": "form",
        "id": "QVCAr8xcTwYI"
      },
      "outputs": [],
      "source": [
        "#@title Animation UI\n",
        "show_ui_in_notebook = True #@param {type:\"boolean\"}\n",
        "\n",
        "ui = create_ui(context, outputs_path)\n",
        "ui.queue(concurrency_count=2, max_size=2)\n",
        "ui.launch(show_api=False, debug=True, inline=show_ui_in_notebook, height=768, share=True, show_error=True)"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "venv",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.5"
    },
    "orig_nbformat": 4,
    "vscode": {
      "interpreter": {
        "hash": "fb02550c4ef2b9a37ba5f7f381e893a74079cea154f791601856f87ae67cf67c"
      }
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}